package com.shushan.home.bean;

import com.android.net.bean.NetBaseBean;
import com.shushan.base.Constants;
import com.shushan.pages.bean.SubjectSyncExerciseBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: IndexBean
 * @Desciption: 首页信息bean
 * @author: yichaohua
 * @date: 2018-08-16
 */
public class IndexBean extends NetBaseBean {

    public int score;
    public int time;

    private List<BannerDataBean> bannerDataBeanList = new ArrayList<BannerDataBean>();
    private List<LearnByDoBean> chineseLearnList = new ArrayList<LearnByDoBean>();
    private List<LearnByDoBean> mathLearnList = new ArrayList<LearnByDoBean>();
    private List<LearnByDoBean> englishLearnList = new ArrayList<LearnByDoBean>();

    private List<SubjectSyncExerciseBean> subjectBeans = new ArrayList<>();

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        JSONArray bannerArray = jsonObject.optJSONArray("banner");
        if(bannerArray != null){
            for (int i = 0;i < bannerArray.length();i++){
                JSONObject object = bannerArray.optJSONObject(i);
                BannerDataBean bannerDataBean = new BannerDataBean();
                bannerDataBean.initByJson(object);
                bannerDataBeanList.add(bannerDataBean);
            }
        }

        JSONObject learnJson = jsonObject.optJSONObject("learn");
        if(learnJson != null){
            JSONArray chineseArray = learnJson.optJSONArray(Constants.SUBJECT_CHINESE_ID + "");
            if(chineseArray != null){
                for (int i = 0;i < chineseArray.length();i++){
                    JSONObject object = chineseArray.optJSONObject(i);
                    LearnByDoBean learnByDoBean = new LearnByDoBean();
                    learnByDoBean.initByJson(object);
                    chineseLearnList.add(learnByDoBean);
                }
            }

            JSONArray mathArray = learnJson.optJSONArray(Constants.SUBJECT_MACH_ID + "");
            if(mathArray != null){
                for (int i = 0;i < mathArray.length();i++){
                    JSONObject object = mathArray.optJSONObject(i);
                    LearnByDoBean learnByDoBean = new LearnByDoBean();
                    learnByDoBean.initByJson(object);
                    mathLearnList.add(learnByDoBean);
                }
            }

            JSONArray englishArray = learnJson.optJSONArray(Constants.SUBJECT_ENGLISH_ID + "");
            if(englishArray != null){
                for (int i = 0;i < englishArray.length();i++){
                    JSONObject object = englishArray.optJSONObject(i);
                    LearnByDoBean learnByDoBean = new LearnByDoBean();
                    learnByDoBean.initByJson(object);
                    englishLearnList.add(learnByDoBean);
                }
            }
        }

        JSONObject rewardobj = jsonObject.optJSONObject("learn_reward");
        if(rewardobj != null){
            score = rewardobj.optInt("score",0);
            time = rewardobj.optInt("time",0);
        }

        JSONObject recommendObj = jsonObject.optJSONObject("recommend");
        if(recommendObj != null){
            SubjectSyncExerciseBean szlxBean = new SubjectSyncExerciseBean();
            JSONObject szlxObj = recommendObj.optJSONObject(Constants.STRANGE_WORDS_EXERCISE);
            JSONObject szObj = szlxObj.optJSONObject(Constants.SUBJECT_CHINESE_ID + "");
            if(szObj != null && szObj.length() > 0){
                szlxBean.initByJson(szObj);
                szlxBean.practiceType = Constants.TYPE_STRANGE_WORDS_EXERCISE;
                subjectBeans.add(szlxBean);
            }

            SubjectSyncExerciseBean kylxBean = new SubjectSyncExerciseBean();
            JSONObject kylxObj = recommendObj.optJSONObject(Constants.SPEAKING_EXERCISE);
            JSONObject kyObj = kylxObj.optJSONObject(Constants.SUBJECT_ENGLISH_ID+"");
            if(kyObj != null && kyObj.length() > 0) {
                kylxBean.initByJson(kyObj);
                kylxBean.practiceType = Constants.TYPE_SPEAKING_EXERCISE;
                subjectBeans.add(kylxBean);
            }

            SubjectSyncExerciseBean dclxBean = new SubjectSyncExerciseBean();
            JSONObject dclxObj = recommendObj.optJSONObject(Constants.ENGLISH_WORDS_EXERCISE);
            JSONObject dcObj = dclxObj.optJSONObject(Constants.SUBJECT_ENGLISH_ID+"");
            if(dcObj != null && dcObj.length() > 0) {
                dclxBean.initByJson(dcObj);
                dclxBean.practiceType = Constants.TYPE_ENGLISH_WORDS_EXERCISE;
                subjectBeans.add(dclxBean);
            }

            SubjectSyncExerciseBean tllxBean = new SubjectSyncExerciseBean();
            JSONObject tllxObj = recommendObj.optJSONObject(Constants.HEARING_EXERCISE);
            JSONObject tlObj = tllxObj.optJSONObject(Constants.SUBJECT_ENGLISH_ID+"");
            if(tlObj != null && tlObj.length() > 0) {
                tllxBean.initByJson(tlObj);
                tllxBean.practiceType = Constants.TYPE_HEARING_EXERCISE;
                subjectBeans.add(tllxBean);
            }

            SubjectSyncExerciseBean kslxBean = new SubjectSyncExerciseBean();
            JSONObject kslxObj = recommendObj.optJSONObject(Constants.ORAL_CALCULATE_EXERCISE);
            JSONObject ksObj = kslxObj.optJSONObject(Constants.SUBJECT_MACH_ID+"");
            if(ksObj != null && ksObj.length() > 0) {
                kslxBean.initByJson(ksObj);
                kslxBean.practiceType = Constants.TYPE_ORAL_CALCULATE_EXERCISE;
                subjectBeans.add(kslxBean);
            }
        }

    }

    public List<BannerDataBean> getBannerDataBeanList() {
        return bannerDataBeanList;
    }

    public void setBannerDataBeanList(List<BannerDataBean> bannerDataBeanList) {
        this.bannerDataBeanList = bannerDataBeanList;
    }

    public List<LearnByDoBean> getChineseLearnList() {
        return chineseLearnList;
    }

    public void setChineseLearnList(List<LearnByDoBean> chineseLearnList) {
        this.chineseLearnList = chineseLearnList;
    }

    public List<LearnByDoBean> getMathLearnList() {
        return mathLearnList;
    }

    public void setMathLearnList(List<LearnByDoBean> mathLearnList) {
        this.mathLearnList = mathLearnList;
    }

    public List<LearnByDoBean> getEnglishLearnList() {
        return englishLearnList;
    }

    public void setEnglishLearnList(List<LearnByDoBean> englishLearnList) {
        this.englishLearnList = englishLearnList;
    }

    public List<SubjectSyncExerciseBean> getSubjectBeans() {
        return subjectBeans;
    }
}
